package com.zoe.onelink.actuate.check;

import com.zoe.onelink.plugin.check.AbstractEnvironmentChecker;
import com.zoe.onelink.plugin.check.model.PropertyCheckResult;
import org.springframework.core.env.Profiles;

import java.util.List;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2022</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2022-09-26
 */
public class DocEnvironmentChecker extends AbstractEnvironmentChecker {

    @Override
    protected List<PropertyCheckResult<?>> doCheck() {
        boolean isProd = this.getEnvironment().acceptsProfiles(Profiles.of("prod"));
        Boolean knife4jEnabled = this.getProperty("knife4j.enable", Boolean.class, false);
        Boolean onelinkDocEnabled = this.getProperty("onelink.doc.enabled", Boolean.class, false);
        // 正式环境且开启在线文档
        if (isProd && knife4jEnabled && onelinkDocEnabled) {
            PropertyCheckResult<Boolean> checkResult = new PropertyCheckResult<Boolean>()
                    .setPropKey("onelink.doc.enabled")
                    .setPropValue(true)
                    .setLevel(PropertyCheckResult.Level.DANGER)
                    .setMessage("生产环境建议关闭在线文档功能,避免接口信息泄漏,以及节省启动生成文档的耗时");
            return List.of(checkResult);
        }
        return null;
    }

}
